package interval;

import java.util.ArrayList;
import java.util.List;

/*
 *@description 汇总区间
 *@author hkfan
 *@version 1.0
 *@create 2025/6/5 16:00
 */
public class LeetCode_228 {
    public List<String> summaryRanges(int[] nums) {
        //1. 定义
        List<String> res = new ArrayList<>();
        //2. 循环
        for (int i = 0; i < nums.length; ) {
            String str = nums[i]+"->";
            int temp = nums[i];
            while (i< nums.length && temp==nums[i]){
                temp++;
                i++;
            }
            str+=nums[i-1];
            res.add(str);
        }
        //3. 遍历整理
        for (int i = 0; i < res.size(); i++) {
            String str = res.get(i);
            String[] strings = str.split("->");
            if (strings[0].equals(strings[1])){
                str=strings[0];
            }
            res.set(i,str);
        }
        return res;

    }
}
